package cn.gson.school;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewResolverRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import cn.gson.school.Interceptor.LoginInterceptor;
import cn.gson.school.Interceptor.RightsInterceptor;

@Configuration
@EnableWebMvc
public class AppMvcConfingurer extends WebMvcConfigurerAdapter {

	@Autowired
	RightsInterceptor rightsInterceptor;

	@Override
	public void configureViewResolvers(ViewResolverRegistry registry) {
		registry.jsp("/WEB-INF/jsp/", ".jsp");
		super.configureViewResolvers(registry);
	}

	@Override
	public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
		configurer.enable();
		super.configureDefaultServletHandling(configurer);
	}

	/**
	 * 注册拦截器
	 */
	@Override
	public void addInterceptors(InterceptorRegistry registry) {

		InterceptorRegistration loginIr = registry.addInterceptor(new LoginInterceptor());
		// 拦截所有请求
		loginIr.addPathPatterns("/**");
		// 排除登录请求
		loginIr.excludePathPatterns("/login");
		// 请求的权限过滤器
	}
}
